from sqlalchemy import Column, Integer, String, \
    Text, ForeignKey, SmallInteger, BigInteger, \
        Date, DateTime
from sqlalchemy.orm import relationship
from datetime import datetime


from app.models import Base
from app import create_session


class Movie(Base):
    id = Column(Integer, primary_key=True)  # 记录id
    title = Column(String(255), unique=True)  # 电影标题
    url = Column(String(255), unique=True)  # 播放的url
    info = Column(Text)                       # 简介
    logo = Column(String(255), unique=True)  # 电影海报
    star = Column(SmallInteger)              # 电影星级
    playnum = Column(BigInteger)             # 播放数
    commentnum = Column(BigInteger)           # 评论数
    area = Column(String(255))        # 地区
    release_time = Column(Date)           # 发布时间
    length = Column(String(100))      # 电影长度
    ctime = Column(DateTime, index=True, default=datetime.now)

    tag_id = Column(Integer, ForeignKey('tag.id')) # 所属标签 外联tag表的id值
    
    comments = relationship("Comment", backref='movie')  # 评论表的外键
    moviecols = relationship("Moviecol", backref='movie')
    previews = relationship("Preview", backref='movie')